
import { action, observable } from 'mobx';
import cartService from '../services/cart/cartService';
import { ShoppingCartInputDto } from '../services/cart/dto/shoppingCartInputDto';
import { ShoppingCartDto } from '../services/cart/dto/shoppingCartDto';

class CartStore {
    @observable products:[]=[]
    @observable cartItems:ShoppingCartDto[]=[]
    @observable cartNum:number

    @action
    async createShoppingCartAsync(input:ShoppingCartInputDto) {
        await cartService.createShoppingCartAsync(input).then((res) => {
            this.products = res.data.result
        })
    }

    @action
    async getMyShoppingCart(){
        await cartService.getShoppingCarts().then((res)=>{
            this.cartItems = res
        })
    }

    @action 
    async updateShoppingCart(input:ShoppingCartInputDto){
        await cartService.updateShoppingCart(input)
    }

    @action
    async getMyShoppingCartCount(){
        await cartService.getMyShoppingCartCount().then((res)=>{
            this.cartNum = res
        })
    }

    @action
    async deleteShoppingCarts(ids: number[]) {
        await cartService.deleteShoppingCarts(ids)
    }
}

export default CartStore 